import React, { Component } from "react";
import Child from "./Child";

class App extends Component {
  state = {
    num: 10,
  };

  fn = () => {
    // this.setState((prevState) => {
    //   return {
    //     num: prevState.num * 2,
    //   };
    // });
    this.setState({
      num: 20,
    });
  };

  render() {
    return (
      <>
        <h2>新版(16.3之后)的生命周期 - {this.state.num}</h2>
        <button onClick={this.fn}>num++</button>
        <Child num={this.state.num} />
      </>
    );
  }
}

export default App;
